package net.myspring.middle.mapper;

import net.myspring.common.mybatis.domain.Page;
import net.myspring.common.mybatis.domain.Pageable;
import net.myspring.common.mybatis.provider.mapper.CrudMapper;
import net.myspring.middle.domain.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;
import java.util.Map;

/**
 * Created by liuj on 16/7/10.
 */
@Mapper
public interface RoleMapper extends CrudMapper<Role,String> {

    List<String> findCodeByAccountId(String accountId);

    List<Role> findAll();

    List<Role> findByPermissionId(String permissionId);

    List<Role> findByAccountId(String accountId);

    Role findByCode(String code);

    Role findByName(String name);

    Page<Role> findPage(Pageable pageable, @Param("p") Map<String, Object> map);

    int savePermissions(@Param("roleId") String roleId, @Param("permissionIds") List<String> permissionIds);

    int deletePermissionByRoleId(String roleId);

    @Cacheable(value = "roles", key = "#p0")
    Role findOne(String id);

    @CacheEvict(value = "roles", key = "#p0.id")
    int update(Role role);
}
